package com.woniuxy.thirdfactory;

import com.woniuxy.secondfactory.Person;

import java.io.IOException;
import java.util.Properties;

/**
 * @Author 罗蔚
 * @Date 2022/3/23 14:37
 * @Description 第三类工厂, 通过读取配置文件来实例化对象
 */
public class PersonThirdFactory {
    public Person getPerson() {
        Properties properties = new Properties();
        try {
            properties.load(PersonThirdFactory.class.getClassLoader().getResourceAsStream("person.properties"));
            Object personClass = properties.get("person");

            Class<?> clazz = Class.forName((String) personClass);
            return (Person) clazz.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
